<template>
  <div class="login">
    <div class="mask">
      <el-row :gutter="20">
        <el-col :span="12">
          <div class="img">
            <img
              src="https://hooray.gitee.io/fantastic-admin-pro-example/assets/login-banner-a565fac8.png"
            />
          </div>
        </el-col>
        <el-col :span="12">
          <div class="login_right">
            <h3>
              欢迎登录 🎶
              <span>Welcome Ticketing Login 🎶</span>
            </h3>
            <el-form ref="form" :rules="rules" :model="form" class="form">
              <el-form-item
                style="margin-bottom: 30px"
                prop="usernmae"
                label-width="70px"
              >
                <b> 用户名 </b>
                <el-input
                  maxlength="5"
                  show-word-limit
                  placeholder="请输入usernmae"
                  v-model="form.usernmae"
                  :prefix-icon="User"
                >
                  <template #prefix>
                    <el-icon class="el-input__icon"><User /></el-icon>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item label-width="70px" prop="password">
                <b> 密码 </b>
                <el-input
                  v-model="form.password"
                  placeholder="请输入密码"
                  :prefix-icon="Ship"
                >
                  <template #prefix>
                    <el-icon class="el-input__icon"><Ship /></el-icon>
                  </template>
                </el-input>
              </el-form-item>
              <a href="/change"> 忘记密码？ </a>
              <el-form-item class="bot">
                <el-button type="primary" @click="onSubmit">login</el-button>
                <el-button @click="resetForm('form')">Reset</el-button>
              </el-form-item>
            </el-form>
          </div>
          <h5>
            还没有账号 ?<a
              :style="{ color: 'salmon', fontSize: '16px' }"
              @click="this.$router.push('/sign')"
            >
              创建新账号
            </a>
          </h5>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
 
 <script>
import { ElMessage } from "element-plus";
import { HttpLogin } from "api";
export default {
  data() {
    return {
      form: {
        usernmae: "",
        password: "",
      },
      rules: {
        usernmae: [
          {
            required: true,
            message: "please enter a User Name ",
            trigger: "blur",
          },
          {
            min: 3,
            max: 5,
            message: "The length is 3 to 5 ",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "please enter the password ",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    async onSubmit() {
      if (this.form.usernmae === "" && this.form.password === "") {
        ElMessage({
          message: "Please enter the content ! ! !",
          type: "warning",
        });
      } else {
        let res = await HttpLogin({ ...this.form });
        ElMessage({
          message: res.data.msg + "!",
          type: res.data.code === 200 ? "success" : "warning",
        });
        console.log(res.data);
        if (res.data.code === 200) {
          this.$router.push("/");
          localStorage.setItem("token", JSON.stringify(res.data.token));
          localStorage.setItem("user", JSON.stringify(res.data.user));
        }
      }
    },
    // 重置数据
    resetForm(form) {
      this.$refs[form].resetFields();
    },
  },
};
</script>

 <style scoped lang='scss'>
a {
  text-decoration: none;
  // color: white;
  cursor: pointer;
}
.login {
  width: 100%;
  height: 100%;
  top: 0px;
  left: 0px;
  position: fixed;
  background-repeat: repeat-x;
  background-image: url("../../assets/img/login.jpg");
  transition: 13s;
  animation-name: login;
  animation-duration: 5s;
  background-size: 100% 100%;
}
h3 {
  line-height: 100px;
  font-size: 30px;
  span {
    font-size: 15px;
    margin-top: -50px;
    display: block;
  }
}
.mask {
  .el-input {
    height: 40px;
    width: 280px;
  }
  b {
    width: 60px;
    float: left;
    font-size: 18px;
  }
  width: 900px;
  height: 500px;
  position: fixed;
  background-color: rgba(255,255,255,.5);
  top: 50%;
  // box-shadow: 0px -2px 40px #f4f4f4 ;
  border: solid 1px #ccc;
  left: 50%;
  overflow: hidden;
  border-radius: 20px;
  transform: translate(-50%, -50%);
}

.img {
  width: 100%;
  height: 500px;
  // background-color: #eeee;

  img {
    margin: 10px;
    margin-left: -30px;
    width: 120%;
    height: 90%;
  }
}
.login_right {
  padding: 10px;
}
.bot {
  margin-top: 30px;
  margin-left: 130px;
}

.login_right a {
  float: right;
  margin-right: 10px;
  font-size: 13px;
}
h5 {
  text-align: center;
}
</style>